{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from stocker import Stocker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MSFT Stocker Initialized. Data covers 1986-03-13 00:00:00 to 2018-03-27 00:00:00.\n"
     ]
    }
   ],
   "source": [
    "microsoft = Stocker('MSFT')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Ex-Dividend</th>\n",
       "      <th>Split Ratio</th>\n",
       "      <th>Adj. Open</th>\n",
       "      <th>Adj. High</th>\n",
       "      <th>Adj. Low</th>\n",
       "      <th>Adj. Close</th>\n",
       "      <th>Adj. Volume</th>\n",
       "      <th>ds</th>\n",
       "      <th>y</th>\n",
       "      <th>Daily Change</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1986-03-13</td>\n",
       "      <td>25.50</td>\n",
       "      <td>29.25</td>\n",
       "      <td>25.5</td>\n",
       "      <td>28.00</td>\n",
       "      <td>3582600.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.058941</td>\n",
       "      <td>0.067609</td>\n",
       "      <td>0.058941</td>\n",
       "      <td>0.064720</td>\n",
       "      <td>1.031789e+09</td>\n",
       "      <td>1986-03-13</td>\n",
       "      <td>0.064720</td>\n",
       "      <td>0.005779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1986-03-14</td>\n",
       "      <td>28.00</td>\n",
       "      <td>29.50</td>\n",
       "      <td>28.0</td>\n",
       "      <td>29.00</td>\n",
       "      <td>1070000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.064720</td>\n",
       "      <td>0.068187</td>\n",
       "      <td>0.064720</td>\n",
       "      <td>0.067031</td>\n",
       "      <td>3.081600e+08</td>\n",
       "      <td>1986-03-14</td>\n",
       "      <td>0.067031</td>\n",
       "      <td>0.002311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1986-03-17</td>\n",
       "      <td>29.00</td>\n",
       "      <td>29.75</td>\n",
       "      <td>29.0</td>\n",
       "      <td>29.50</td>\n",
       "      <td>462400.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.067031</td>\n",
       "      <td>0.068765</td>\n",
       "      <td>0.067031</td>\n",
       "      <td>0.068187</td>\n",
       "      <td>1.331712e+08</td>\n",
       "      <td>1986-03-17</td>\n",
       "      <td>0.068187</td>\n",
       "      <td>0.001156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1986-03-18</td>\n",
       "      <td>29.50</td>\n",
       "      <td>29.75</td>\n",
       "      <td>28.5</td>\n",
       "      <td>28.75</td>\n",
       "      <td>235300.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.068187</td>\n",
       "      <td>0.068765</td>\n",
       "      <td>0.065876</td>\n",
       "      <td>0.066454</td>\n",
       "      <td>6.776640e+07</td>\n",
       "      <td>1986-03-18</td>\n",
       "      <td>0.066454</td>\n",
       "      <td>-0.001734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1986-03-19</td>\n",
       "      <td>28.75</td>\n",
       "      <td>29.00</td>\n",
       "      <td>28.0</td>\n",
       "      <td>28.25</td>\n",
       "      <td>166300.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.066454</td>\n",
       "      <td>0.067031</td>\n",
       "      <td>0.064720</td>\n",
       "      <td>0.065298</td>\n",
       "      <td>4.789440e+07</td>\n",
       "      <td>1986-03-19</td>\n",
       "      <td>0.065298</td>\n",
       "      <td>-0.001156</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Date   Open   High   Low  Close     Volume  Ex-Dividend  Split Ratio  \\\n",
       "0 1986-03-13  25.50  29.25  25.5  28.00  3582600.0          0.0          1.0   \n",
       "1 1986-03-14  28.00  29.50  28.0  29.00  1070000.0          0.0          1.0   \n",
       "2 1986-03-17  29.00  29.75  29.0  29.50   462400.0          0.0          1.0   \n",
       "3 1986-03-18  29.50  29.75  28.5  28.75   235300.0          0.0          1.0   \n",
       "4 1986-03-19  28.75  29.00  28.0  28.25   166300.0          0.0          1.0   \n",
       "\n",
       "   Adj. Open  Adj. High  Adj. Low  Adj. Close   Adj. Volume         ds  \\\n",
       "0   0.058941   0.067609  0.058941    0.064720  1.031789e+09 1986-03-13   \n",
       "1   0.064720   0.068187  0.064720    0.067031  3.081600e+08 1986-03-14   \n",
       "2   0.067031   0.068765  0.067031    0.068187  1.331712e+08 1986-03-17   \n",
       "3   0.068187   0.068765  0.065876    0.066454  6.776640e+07 1986-03-18   \n",
       "4   0.066454   0.067031  0.064720    0.065298  4.789440e+07 1986-03-19   \n",
       "\n",
       "          y  Daily Change  \n",
       "0  0.064720      0.005779  \n",
       "1  0.067031      0.002311  \n",
       "2  0.068187      0.001156  \n",
       "3  0.066454     -0.001734  \n",
       "4  0.065298     -0.001156  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_history = microsoft.stock\n",
    "stock_history.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('msft1.txt','w')\n",
    "f.write(str(stock_history.head()))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(['Adj. Close'],\n",
       " 96.77,\n",
       " Timestamp('2018-03-12 00:00:00'),\n",
       " 0.060097123934714,\n",
       " Timestamp('1986-03-24 00:00:00'),\n",
       " 89.47,\n",
       " Timestamp('2018-03-27 00:00:00'))"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "microsoft.plot_stock()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('msft2.txt','w')\n",
    "f.write(str(microsoft.plot_stock()))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(['Daily Change'],\n",
       " 2.082220461981997,\n",
       " Timestamp('2008-10-13 00:00:00'),\n",
       " -3.3400000000000034,\n",
       " Timestamp('2017-12-04 00:00:00'),\n",
       " -5.469999999999999,\n",
       " Timestamp('2018-03-27 00:00:00'))"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "microsoft.plot_stock(start_date = '2000-01-03', end_date = '2018-01-16', \n",
    "                     stats = ['Daily Change'], plot_type='pct')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('msft3.txt','w')\n",
    "f.write(str(microsoft.plot_stock(start_date = '2000-01-03', end_date = '2018-01-16', \n",
    "                     stats = ['Daily Change'], plot_type='pct')))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(['Adj. Volume'],\n",
       " 591052200.0,\n",
       " Timestamp('2006-04-28 00:00:00'),\n",
       " 7425503.0,\n",
       " Timestamp('2017-11-24 00:00:00'),\n",
       " 53704562.0,\n",
       " Timestamp('2018-03-27 00:00:00'))"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "microsoft.plot_stock(start_date = '2000-01-03', end_date = '2018-01-16', \n",
    "                     stats = ['Adj. Volume'], plot_type='pct')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('msft4.txt','w')\n",
    "f.write(str(microsoft.plot_stock(start_date = '2000-01-03', end_date = '2018-01-16', \n",
    "                     stats = ['Adj. Volume'], plot_type='pct')))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('MSFT',\n",
       " Timestamp('1986-03-13 00:00:00'),\n",
       " Timestamp('2018-01-16 00:00:00'),\n",
       " 100,\n",
       " 8829.10585899871)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "microsoft.buy_and_hold(start_date='1986-03-13', end_date='2018-01-16', nshares=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('msft5.txt','w')\n",
    "f.write(str(microsoft.buy_and_hold(start_date='1986-03-13', end_date='2018-01-16', nshares=100)))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('MSFT',\n",
       " Timestamp('1999-01-05 00:00:00'),\n",
       " Timestamp('2002-01-03 00:00:00'),\n",
       " 100,\n",
       " -56.9165992219002)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "microsoft.buy_and_hold(start_date='1999-01-05', end_date='2002-01-03', nshares=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('msft6.txt','w')\n",
    "f.write(str(microsoft.buy_and_hold(start_date='1999-01-05', end_date='2002-01-03', nshares=100)))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Adj. Close</th>\n",
       "      <th>delta</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>361</th>\n",
       "      <td>2016-09-01</td>\n",
       "      <td>55.966886</td>\n",
       "      <td>-1.319902</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169</th>\n",
       "      <td>2015-11-27</td>\n",
       "      <td>51.353167</td>\n",
       "      <td>-1.128169</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>289</th>\n",
       "      <td>2016-05-20</td>\n",
       "      <td>48.886934</td>\n",
       "      <td>0.847661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>506</th>\n",
       "      <td>2017-03-31</td>\n",
       "      <td>64.816957</td>\n",
       "      <td>0.580521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>2015-09-18</td>\n",
       "      <td>41.122995</td>\n",
       "      <td>0.571162</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Date  Adj. Close     delta\n",
       "361 2016-09-01   55.966886 -1.319902\n",
       "169 2015-11-27   51.353167 -1.128169\n",
       "289 2016-05-20   48.886934  0.847661\n",
       "506 2017-03-31   64.816957  0.580521\n",
       "120 2015-09-18   41.122995  0.571162"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "microsoft.changepoint_date_analysis()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "f = open('msft7.txt','w')\n",
    "f.write(str(microsoft.changepoint_date_analysis()))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "model, future = microsoft.create_prophet_model(days=30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "f = open('msft8.txt','w')\n",
    "f.write(str(microsoft.create_prophet_model(days=30)))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
